#ifndef PROCESS_H
#define PROCESS_H

#include <boost/shared_ptr.hpp>
#include <deque>

using std::deque;
using boost::shared_ptr;

namespace engine {

	namespace core {

        class Kernel;
        struct Message;
		
		typedef deque< shared_ptr<Message> > MessageQueue;
		
		class Process {
			private:
				MessageQueue m_Inbox;
				MessageQueue m_Outbox;

				shared_ptr<Kernel> m_Parent;
				bool m_IsThread;

				int run();

				uint m_PID;
			protected:
				virtual bool processRecievedMessage(shared_ptr<Message> msg) = 0;
				void sendMessage(shared_ptr<Message> msg);
				
			public:
				Process();
				Process(const shared_ptr<Kernel> parent, bool isThread=false);
				
				void setParent(const shared_ptr<Kernel> parent);
				
				virtual ~Process();
				
				virtual bool initialize() = 0;
				virtual bool prepare(float dT) = 0;
				virtual void update() = 0;
				virtual void shutdown() = 0;
				
				int processInbox();

				const MessageQueue& getOutbox();
				void clearOutbox() { m_Outbox.clear(); }

				void receiveMessage(shared_ptr<Message> msg);

				uint getPID() { return m_PID; }
				void setPID(uint PID) { m_PID = PID; }
		};
	}
}
#endif
